<!--
 * @Author: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @Date: 2024-08-29 10:59:23
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-09-25 14:36:01
 * @FilePath: \ft-apply-admin\src\views\applicationDetails\Modals\RBModal.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <BasicModal :show="show" :title="current.process" width="30%" :widthComfirm="true" @comfirm="confirm"
    @closeModal="show = false">
    <template #content>
      <CommonForm :formList="formList" ref="formRef" labelWidth='110px'></CommonForm>
    </template>
  </BasicModal>
</template>




<script setup lang='ts'>
import BasicModal from "@/views/ApplicationDetails/Modals/BasicModal.vue";
import type { IndexFormItem } from "@/views/ApplicationDetails/application-type.ts";
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import { ref } from "vue";
import { message } from "ant-design-vue";
import { selectUserByRole, selectCommonConfigFoChildren, changeSchoolInfo, updateOnDutyTime } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
const store = comStores();
const formList = ref<IndexFormItem>();
const formRef = ref<any>(null);
const show = ref<boolean>(false)
const emit = defineEmits(['reRender'])
const confirm = async () => {
  const res = await formRef.value.submitForm();
  if (!res) return
  let form = {
    cascader: []
  };
  res.forEach(el => {
    form[el.name] = el.value
  })
  const { resumeId } = store.currentResume;
  const { userName } = store.userInFor;
  const { processId, process } = current.value;

  if (current.value.process == '待录取') {
    let param = {
      resumeId,
      processId,
      onDutyTime: res[0].value+ " 00:00:00"
    }
    const data = await updateOnDutyTime(param)
    if (data && data.code == '10000') {
      message.success("更新成功");
      emit('reRender')
      show.value = false
    } else {
      message.error(data.msg)
    }
    return
  }
  let param: any = {
    resumeId: resumeId,
    processId: processId,
    operator: userName,
    remark: res[2].value,
    school: form.cascader[0],
    subject: form.cascader[1],
    grade: form.cascader[2],
    process: process,
    teacher: current.value.process === '转正' ? null : res[1].value
  }
  let data = await changeSchoolInfo(param)
  console.log(data, '===>data');
  if (data && data.code == '10000') {
    message.success("更新成功");
    emit('reRender')
    show.value = false
  } else {
    message.error(data.msg)
  }
}
const current = ref<any>({ process: "" })
const HRList = ref<{ label: string, value: string | number }[]>([])
const showDialog = async (val) => {
  current.value = val;
  console.log(val, '===>val')
  if (val.process == '待录取') {
    formList.value = [
      { label: "预计到岗时间", name: "onDutyTime",required: false, value: "", component: 'datePicker', format: "YYYY-MM-DD" },
    ]
    show.value = true;
    return
  }
  const { school, subject, grade, process } = val
  formList.value = [
    { label: "试用", name: "cascader", value: "", component: 'cascader', options: [] },
    { label: "导师", name: "entryTeacher", value: "", component: 'select', options: [] },
    { label: "备注", name: "remark", value: "", component: 'textarea', required: false },
  ]
  const data = await selectCommonConfigFoChildren({ type: 1 });
  const teacher = await selectUserByRole("MENTOR") //导师
  formList.value[0].options = data.data;
  formList.value[0].label = current.value.process;
  formList.value[0].value = [school, subject, grade];
  formList.value[1].options = teacher.data;
  formList.value[1].value = val.teacher;
  if (process === '转正') {
    formList.value[1].show = false
  }
  formList.value[2].value = "";
  show.value = true;
}
defineExpose({
  showDialog
})
</script>

<style lang="less" scoped></style>
